package ln.javatest.day01.demo02;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

//使用新的工具类
public class DruidDemo02 {
    public static void main(String[] args) {
        Connection conn = null;
        PreparedStatement pstat = null;
        //完成一个添加的操作
        //给user表添加一条记录
        try {
            //1.获取连接
            conn = JDBCUtils.getConnection();
            //2.定义sql
            String sql = "insert into user values(null,?,?)";
            //3.获取pstat对象
            pstat = conn.prepareStatement(sql);
            //4.给？赋值
            pstat.setString(1,"王五");
            pstat.setString(2,"123");
            //5.执行sql
            int count = pstat.executeUpdate();
            System.out.println(count);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            //6.释放资源
            JDBCUtils.close(pstat,conn);
        }
    }
}
